<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>财务管理系统 - 登录</title>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        :root {
            --primary-color: #4361ee;
            --hover-color: #3a56d4;
            --bg-color: #f8f9fa;
            --card-color: #ffffff;
            --text-color: #2c3e50;
        }

        body {
            margin: 0;
            padding: 0;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: var(--bg-color);
            color: var(--text-color);
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-image: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
        }

        .login-container {
            width: 380px;
            padding: 40px 30px;
            background: var(--card-color);
            border-radius: 12px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }

        .login-container:hover {
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
        }

        .logo {
            text-align: center;
            margin-bottom: 30px;
        }

        .logo h1 {
            color: var(--primary-color);
            font-size: 28px;
            font-weight: 600;
            margin-bottom: 5px;
            letter-spacing: 1px;
        }

        .logo p {
            color: #7f8c8d;
            font-size: 14px;
        }

        .el-form-item {
            margin-bottom: 25px;
        }

        .el-input__inner {
            height: 46px;
            line-height: 46px;
            border-radius: 8px;
            padding-left: 15px;
        }

        .el-button {
            width: 100%;
            height: 46px;
            border-radius: 8px;
            background-color: var(--primary-color);
            font-size: 16px;
            letter-spacing: 1px;
            transition: all 0.3s;
        }

        .el-button:hover {
            background-color: var(--hover-color);
        }
    </style>
</head>
<body>
<div id="app">
    <div class="login-container">
        <div class="logo">
            <h1>财务管理系统</h1>
            <p>Financial Management System</p>
        </div>

        <el-form :model="user" :rules="rules" ref="loginForm">
            <el-form-item prop="userName">
                <el-input
                        v-model="user.userName"
                        placeholder="请输入用户名"
                        prefix-icon="el-icon-user">
                </el-input>
            </el-form-item>

            <el-form-item prop="userPassword">
                <el-input
                        v-model="user.userPassword"
                        type="password"
                        placeholder="请输入密码"
                        prefix-icon="el-icon-lock"
                        show-password>
                </el-input>
            </el-form-item>

            <el-form-item>
                <el-button
                        type="primary"
                        @click="login"
                        :loading="loading">
                    登 录
                </el-button>
            </el-form-item>
        </el-form>
    </div>
</div>

<!-- 引入Vue和Element UI -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script>
    new Vue({
        el: '#app',
        data() {
            return {
                user: {
                    userName: '',
                    userPassword: ''
                },
                loading: false,
                rules: {
                    userName: [
                        { required: true, message: '请输入用户名', trigger: 'blur' }
                    ],
                    userPassword: [
                        { required: true, message: '请输入密码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            login() {
                this.$refs.loginForm.validate(valid => {
                    if (valid) {
                        this.loading = true;
                        axios.post('auth/login', this.user)
                            .then(response => {
                                if (response.data.success === true) {
                                    localStorage.setItem('token', response.data.token);
                                    this.$message.success('登录成功');
                                    setTimeout(() => {
                                        window.location.href = '/PFSystem/financialRecord.html?userId=' + response.data.userId;
                                    }, 1000);
                                } else {
                                    this.$message.error('登录失败: ' + (response.data.message || '未知错误'));
                                }
                            })
                            .catch(err => {
                                this.$message.error('登录失败: ' + (err.response?.data?.message || err.message));
                            })
                            .finally(() => {
                                this.loading = false;
                            });
                    }
                });
            }
        }
    });
</script>
</body>
</html>